package com.lhkj.iams.wechat.config.mp.handler;

import com.lhkj.iams.wechat.config.mp.builder.TextBuilder;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @desc 扫码处理
 */
@Component
public class ScanHandler extends AbstractHandler {

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> map,
        WxMpService wxMpService,
        WxSessionManager wxSessionManager) throws WxErrorException {
        // 扫码事件处理
        this.logger.info("扫码用户 OPENID: " + wxMessage.getFromUser());
        //todo 处理扫码相关的操作
        try {
            //从diamond中获取标准话术
            return new TextBuilder().build("感谢订阅", wxMessage, wxMpService);
        } catch (Exception e) {
            this.logger.error(e.getMessage(), e);
        }

        return null;
    }
}

